﻿/** 
 * Copyright 2010 NUMKIT.COM (contact: opensource@numkit.com)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @author 陈超
 * @version 1.0
 */
class Config {
	public var fontSpace:Number;
	//color
	public var backgroundColor:Number = 0x000000;
	public var textColor:Number = 0xFFFF00;
	public var labelFormat:Number = Piece.LABEL_FORMAT_BOTH;
	public var directLineColor:Number = 0xFFFF00;
	public static var formatter:TextFormat;
	public function Config(node:XMLNode) {
		if (formatter == undefined) {
			formatter = new TextFormat();
			formatter.size = 12;
			formatter.color = textColor;
		}
		if (node.nodeName != "config") {
			throw new Error("Not A config Node!");
		}
		var nodeName:String;
		for (var child:XMLNode = node.firstChild; child != null; child=child.nextSibling) {
			nodeName = child.nodeName;
			if (nodeName == "backgroundColor") {
				var temp:Number = Number(child.firstChild.nodeValue);
				if (!isNaN(temp)) {
					backgroundColor = temp;
				}
			} else if (nodeName == "textColor") {
				var temp:Number = Number(child.firstChild.nodeValue);
				if (!isNaN(temp)) {
					textColor = temp;
					formatter.color = textColor;
				}
			} else if (nodeName == "directLineColor") {
				var temp:Number = Number(child.firstChild.nodeValue);
				if (!isNaN(temp)) {
					directLineColor = temp;
				}
			} else if (nodeName == "labelFormat") {
				var temp:String = String(child.firstChild.nodeValue);
				if (temp == "value") {
					labelFormat = Piece.LABEL_FORMAT_VALUE;
				} else if (temp == "percent") {
					labelFormat = Piece.LABEL_FORMAT_PERCENT;
				} else if (temp == "both") {
					labelFormat = Piece.LABEL_FORMAT_BOTH;
				} else {
					labelFormat = Piece.LABEL_FORMAT_BOTH;
				}
			}
		}
	}
}
